//
//  HSQSortDropMenuView.m
//  LiTianDecoration
//
//  Created by administrator on 2018/8/3.
//  Copyright © 2018年 administrator. All rights reserved.
//

#import "HSQSortDropMenuView.h"
#import "HSQClassificationListCell.h"
#import "HSQCategoryListModel.h"

@interface HSQSortDropMenuView ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;



@end

@implementation HSQSortDropMenuView

- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        // 创建tableView
        [self SetUpTableView];
    }
    
    return self;
}

/**
 * @brief 创建tableView
 */
- (void)SetUpTableView{
    
    UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
    
    tableView.backgroundColor = KViewBackGroupColor;
    
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    tableView.dataSource = self;
    
    tableView.delegate = self;
    
    [tableView registerClass:[HSQClassificationListCell class] forCellReuseIdentifier:@"HSQClassificationListCell"];
    
    [self addSubview:tableView];
    
    self.tableView = tableView;
}

- (void)setCategoryList:(NSMutableArray *)categoryList{
    
    _categoryList = categoryList;
    
    [self.tableView reloadData];
}

- (void)setCategorySort:(NSString *)categorySort{
    
    _categorySort = categorySort;
    
    [self.tableView reloadData];
}

#pragma mark - UITableViewDelegate,UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
     return self.categoryList.count;
}

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 50;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    HSQClassificationListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HSQClassificationListCell" forIndexPath:indexPath];
    
    cell.model = self.categoryList[indexPath.row];
    
    if (indexPath.row == self.categorySort.integerValue)
    {
        cell.CategoryName_Label.textColor = RGB(238, 58, 68);
        cell.Category_imageView.hidden = NO;
    }
    else
    {
        cell.CategoryName_Label.textColor = RGB(71, 71, 71);
        cell.Category_imageView.hidden = YES;
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    HSQCategoryListModel *model = self.categoryList[indexPath.row];
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(CategoryMenuSelectedClickEvents:model:)]) {
        
        [self.delegate CategoryMenuSelectedClickEvents:self.tableView model:model];
    }
}







@end
